package com.jy.api.signUpReq.stock;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.jy.api.domain.ProductMold;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by xiaohua on 2018/7/14.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class InventoryCheckReq {

    @NotNull(message = "参数错误")
    private String storeId;

    private String operatorId;

    /**
     * 操作人名称
     */
    private String operatorName;

    /**
     * 种类
     */
    private int kind;


    /**
     * 盘盈总件数量
     */
    private int wholeProfit;

    /**
     * 盘亏总件数量
     */
    private int wholeLosses;

    /**
     * 备注
     */
    private String notes;

    private List<CheckInventory> checkInventories;

    /**
     * 总数量
     */
    private Integer countNum;

    /**
     * 库存主记录识别码
     */
    private String checkCode;

    /**
     * 出入库主记录识别码
     */
    private String receiptCode;

    private ProductMold mold;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor(suppressConstructorProperties = true)
    public static class CheckInventory {

        @NotNull(message = "参数有误")
        private Long invId;

        @NotNull(message = "参数有误")
        private String productName;

        @NotNull(message = "参数有误")
        private int stockPrice;

        @NotNull(message = "参数有误")
        /**
         * 规格
         */
        private int capacity;
        /**
         * 实际总件数
         */
        @NotNull(message = "参数有误")
        private int checkWholeQty;
        /**
         * 应有件数
         */
        @NotNull(message = "参数有误")
        private int accurateWholeQty;
        /**
         * 备注
         */
        private String notes;

        /**
         * 校验出入库方式 true为一种方式 false （有入库也有出库）
         * checkWholeQty(实际件数)
         * accurateWholeQty（应有件数）
         *
         * @return
         */
        public String checkSockType() {
            if (checkWholeQty == accurateWholeQty) {
                return "NO";
            } else if (checkWholeQty - accurateWholeQty < 0) {
                return "CHECK-OUT";
            } else {
                return "CHECK-IN";
            }

        }


    }
}
